public class Sort {
    //插入
    //时间复杂度O(N^2)
    //有序情况下可以到O(N)
    //稳定
    public void insert(int[] array){
        for(int i = 1; i < array.length; i++){
            int key = array[i];
            int j = i - 1;
            for(; j >= 0; j--){
                if(array[j] > key){
                    array[j + 1] = array[j];
                }else{
                    break;
                }
            }
            array[j + 1] = key;
        }
    }

    public void shell(int[] array, int gap){
        for(int i = gap; i < array.length; i++){
            int key = array[i];
            int j = i - gap;
            for(; j >= 0; j -= gap){
                if(array[j] > key){
                    array[j + gap] = array[j];
                }else{
                    break;
                }
            }
            array[j + gap] = key;
        }
    }
    public void shellSort(int[] array){
        int gap = array.length;
        while(gap > 1){
            gap >>>= 1;
            shell(array, gap);
        }
        shell(array, 1);
    }

}
